//
//  BPCommonViewController.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/10/20.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "BPCommonViewController.h"
#import "PCArrowItm.h"
#import "PCLabelItem.h"
#import "PersonCenterGroup.h"
#import "PersonCenterItem.h"
#import "PersonCenterCellView.h"

@interface BPCommonViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray *groups;

@end

@implementation BPCommonViewController

- (NSMutableArray *)groups
{
    if (_groups == nil)
    {
        self.groups = [NSMutableArray array];
    }
    return _groups;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tableView =[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.delegate=self;
    tableView.dataSource=self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tableView];
    _tableView=tableView;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    // Do any additional setup after loading the view.
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    PersonCenterGroup *group = self.groups[section];
    return group.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PersonCenterCellView *cell = [PersonCenterCellView cellWithTableView:tableView];
    PersonCenterGroup *group = self.groups[indexPath.section];
    cell.item = group.items[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PersonCenterGroup *group = self.groups[indexPath.section];
    PersonCenterItem *item = group.items[indexPath.row];
    
    if (item.destVcClass) {
        UIViewController *destVc = [[item.destVcClass alloc] init];
        destVc.title = item.title;
        [self.navigationController pushViewController:destVc animated:YES];
    }
    if (item.operation) {
        item.operation();
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
